Skip to main content

All Questions

Tagged with
0votes
1answer
110views

uncomment the line upon search string while ignoring case in a file

Below is my cron file entries: #Ansible: test2 */15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out # #...
Ashar's user avatar
0votes
2answers
291views

insert block of lines only before first matched pattern

i need to insert the below lines (after variable substitution) before the first matched string which is server { in /etc/nginx/nginx.conf Variable: website=www.hello.com Block of lines: server { # ...
Ashar's user avatar
-1votes
1answer
54views

Search & replace for a string separated by whitespace upon substring match found

Below is a sample file content: cat sample.txt -server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler....
Ashar's user avatar
1vote
5answers
1kviews

Replace hyphen(s) with underscore(s) within angle brackets in a file

I’m aware of how to replace string; e.g., replace hyphen with underscore in a file. However, I wish to replace all hyphens with underscore for all text that falls within angle brackets in a given file....
Ashar's user avatar
0votes
2answers
1kviews

Replace specified strings in file with strings from other file with sed [duplicate]

I have two files like this. file1 line 1 line 2 ... (more lines) aaa PLACEHOLDER bbb ccc ... (more lines) ddd PLACEHOLDER eee fff ... (more lines) etc file2 NEWTEXT1 NEWTEXT2 ... (more lines) There ...
tom's user avatar
  • 77
0votes
2answers
493views

How to do find and replace strings on file after it is being modified

Trying to achieve following: 1) New file gets uploaded with the same file name but with new content 2) Event triggers that checks the file for specific strings and replaces them 3) The file can be ...
Lauris Kārkliņš's user avatar
2votes
1answer
2kviews

How to express beginning and end of line in sed

I want to use sed to replace every '} that comes at the end of the line to "}. I wrote: sed -i -e "s/'}$/\"}$/g" But this replaces it to: "}$. What is wrong? How can I use regex in my sed to express ...
user9371654's user avatar
2votes
3answers
585views

Conditionally replace lines of file1 with the corresponding lines of file2

For example, I have two files: file1: 1 4 X 5 X 7 file2: 2 3 5 X X 1 I want to replace X-lines of file1 with whatever is in file2 on the corresponding line: result: 1 4 5 5 X 7 I prefer the ...
Fibo Kowalsky's user avatar
8votes
4answers
1kviews

Rename multiple files with 2 conditions/replacements in one line?

I'm trying to rename a few images: IMG_1.JPG IMG_2.JPG IMG_3.JPG I want to replace IMG with img and .JPG with .jpg - I know how to do the second part: $ rename 's/\.JPG$/\.jpg/' *.JPG My problem is ...
treyBake's user avatar
0votes
1answer
597views

regex to replace a word in a block in a file?

If I have: <Directory /> words allow bus </Directory> Is there a regex that can replace allow with something else and keep the other words and the block intact? So it should look like:...
W.Smith's user avatar
1vote
4answers
2kviews

Removing part of all file name in a folder?

My camera stores photos in the following format: DSC_0001 (2015_07_30 10_34_56 UTC).NEF With the number after DSC_ iterating, and the brackets specifying the time and date, however all the time and ...
user avatar
0votes
1answer
114views

How to Replace a string by another in a text file

I would like to replace a given string in a text file into by another, but with one extra detail. Example: If the file content's is : Library Hello1 =============== any text here version: 0.1 ------...
Pedro's user avatar
0votes
1answer
48views

Replacing different files from different folders

He everybody, I couldn't find an answer to my question, so here goes: I want to make a "job" that replaces / distributes 10000+ PDF-files from 1 directory to a unique folder where "the same" PDF (...
John D's user avatar
2votes
2answers
626views

Using sed (or anything useful) to replace strings with relative content

Usually to replace strings across multiple files, one simply needs to use sed -i 's/string1/string2/g' * However, how could I use the sed command (or anything that works, really) to replace things ...
esote's user avatar
0votes
1answer
798views

Replacing one column with another column in csv files [duplicate]

I have a file1 with the following: 1,joe,jim,bob,sally,mark,sue,etc,etc 2,julie,barbra,joe,jim,bob,sally,mark,sue,etc,etc 1,clarie,mike,joe,jim,bob,sally,,etc,etc 2,matt,alivia,joe,jim,bob,mark,sue,...
stevem0's user avatar

153050per page
close